<?php

/**
 * Description of AdversManager_PDO
 *
 * @author FFOZEU
 */
namespace Applications\Modules\Advers\Models;

if( !defined('IN') ) die('Hacking Attempt');

class AdversManager_PDO extends AdversManager{
    
    public function getAdvers(){
        $sql = 'SELECT b.*
                FROM '.$this->nameTable.' as b
                ORDER BY b.id';
        $obj=$this->dao->query($sql);
        
        return $this->fecthAssoc_data($obj, $this->name);
                
    }
    
    public function addAdvers(array $param){
        $objData = new Advers($param);
        $sql='INSERT INTO '.$this->nameTable.'
              SET image = :image, lien = :lien, date_debut = :date_debut, date_fin = :date_fin, position = :position, width = :width, height = :height';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':image',$objData->getImage());
        $req->bindParam(':lien',$objData->getLien());
        $req->bindParam(':date_debut',$objData->getDate_debut());
        $req->bindParam(':date_fin',$objData->getDate_fin());
        $req->bindParam(':position',$objData->getPosition());
        $req->bindParam(':width',$objData->getWidth());
        $req->bindParam(':height',$objData->getHeight());
        
        return $req->execute();
    }
    
    public function updateAdvers(array $param){
        $objData = new Advers($param);
        $sql='UPDATE '.$this->nameTable.'
              SET image = :image, lien = :lien, date_debut = :date_debut, date_fin = :date_fin, position = :position, width = :width, height = :height
              WHERE id = :id';
        $req=$this->dao->prepare($sql);
        $req->bindParam(':image',$objData->getImage());
        $req->bindParam(':lien',$objData->getLien());
        $req->bindParam(':date_debut',$objData->getDate_debut());
        $req->bindParam(':date_fin',$objData->getDate_fin());
        $req->bindParam(':position',$objData->getPosition());
        $req->bindParam(':width',$objData->getWidth());
        $req->bindParam(':height',$objData->getHeight());
        
        return $req->execute();
    }
    
    public function getAdversById($id){
        
        return $this->fecthRow_data($this->findById($this->nameTable, $id), $this->name);
    }
    
    public function deleteAdvers(array $id){
        
        return $this->delete($this->nameTable, $id);
    }
    
    public function getActiveAdvers(){
        $sql = 'SELECT b.*
                FROM '.$this->nameTable.' as b
                WHERE b.etat=1 AND "'.date('Y-m-d H:i:s').'" BETWEEN b.date_debut and b.date_fin
                ORDER BY b.position, b.id';
        $obj=$this->dao->query($sql);
        
        return $this->fecthAssoc_data($obj, $this->name);
    }
}

?>
